package 力扣.双指针.最短区间;

public class 长度最小的子数组209 {
    public int minSubArrayLen(int target, int[] nums) {
           if (nums == null || nums.length == 0){
               return 0;
           }
           int ans = Integer.MAX_VALUE;
           final int N = nums.length;
           int left = -1;
           int sum = 0;
        for (int i = 0; i < N; i++) {
            int t = nums[i];
            sum += t;
            while (sum >= target){
                if (ans > i - left){
                    ans = i - left;
                }
                sum -= nums[++left];
            }
            //此时一定不满足条件
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
}
